[...slug].vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <!-- 店铺商品列表 @zjf-2020-12-30 -->
  2. <template>
  3. <div class="self_background">
  4. <StoreHeaderCat ref="headercat" @sendGoodsName="sendGoodsName"/>
  5. <div
  6. class="sld_store_goods_list clearfix"
  7. >
  8. <!-- 左侧分类 start -->
  9. <div
  10. v-loading="cat_wrap_loading"
  11. class="left_cat_wrap"
  12. >
  13. <template
  14. v-for="(item, index) in storeData.cat"
  15. :key="index"
  16. >
  17. <dl
  18. :class="{
  19. store_cat_item: true,
  20. on: !(item.openFlag != undefined && !item.openFlag),
  21. }"
  22. >
  23. <dt class="grade_one_cat">
  24. <a
  25. @click="(e) => { e.preventDefault(); clacRouteParams('/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item.innerLabelId, true)}"
  26. :to="'/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item.innerLabelId"
  27. >
  28. {{ item.innerLabelName }}
  29. </a>
  30. <i
  31. v-if="item.children.length"
  32. class="more"
  33. @click="toggleOpenFlag(index)"
  34. ></i>
  35. </dt>
  36. <dd
  37. v-if="
  38. item.children.length &&
  39. !(item.openFlag != undefined && !item.openFlag)
  40. "
  41. >
  42. <a
  43. v-for="(item_child, index_child) in item.children"
  44. :key="index_child"
  45. @click="(e) => { e.preventDefault(); clacRouteParams('/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item_child.innerLabelId, true)}"
  46. :to="'/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item_child.innerLabelId"
  47. >
  48. {{ item_child.innerLabelName }}
  49. </a>
  50. </dd>
  51. </dl>
  52. </template>
  53. </div>
  54. <!-- 左侧分类 end -->
  55. <!-- 右侧商品 start -->
  56. <div
  57. v-loading="firstLoading"
  58. :class="{
  59. right_goods_wrap: true,
  60. fr: storeData.cat.length,
  61. no_cate_goods_wrap: !storeData.cat.length,
  62. }"
  63. >
  64. <div class="store_goods_search_nav">
  65. <span :class="{ active: sort == 0 }" >{{
  66. L["综合"]
  67. }}</span>
  68. <div class="sld_store_goods_total_num">
  69. {{ L["共"] }} {{ storeData.goods.pagination.total
  70. }} {{ L["件相关商品"] }}
  71. </div>
  72. </div>
  73. <ul class="sld_store_goods_list_wrap">
  74. <li
  75. v-for="(item, index) in firstLoading
  76. ? skeletonData.goods
  77. : storeData.goods.list"
  78. :key="index"
  79. >
  80. <div class="sld_goods_img">
  81. <router-link
  82. target="_blank"
  83. :to="'/goods/detail/'+ calcProductName(item.goodsDefaultName) +'_'+ item.defaultProductId"
  84. >
  85. <img :src="item.goodsImage" style="display: block" />
  86. </router-link>
  87. </div>
  88. <div class="sld_goods_name_wrap">
  89. <router-link
  90. target="_blank"
  91. :to="'/goods/detail/'+ calcProductName(item.goodsDefaultName) +'_'+ item.defaultProductId"
  92. :title="item.goodsName"
  93. v-html="item.goodsName"
  94. class="sld_goods_name"
  95. >
  96. </router-link>
  97. </div>
  98. <p class="clearfix">
  99. <span class="sld_goods_price fl"
  100. ><em>{{
  101. item.goodsMoney == null ? "Contact us to give you an individual quote" : item.goodsMoney
  102. }}</em></span
  103. >
  104. </p>
  105. <div class="promotion_tag">
  106. <template v-if="item.activityList && item.activityList.length">
  107. <div style="display: flex">
  108. <div
  109. v-for="(item_activity, index_activity) in item.activityList"
  110. :key="index_activity"
  111. >
  112. <span class="promotion_tag_text">{{
  113. item_activity.promotionName
  114. }}</span>
  115. </div>
  116. </div>
  117. </template>
  118. <button
  119. class="sld_collect_wrap fr flex_row_center_center"
  120. :class="{ collect_active: item.isFollowGoods }"
  121. @click="collect(item.defaultProductId, item.isFollowGoods)"
  122. >
  123. <img
  124. src="/goods/collection.png"
  125. alt=""
  126. v-show="item.isFollowGoods == true"
  127. style="width: 20px; height: 20px"
  128. />
  129. <img
  130. src="/goods/no_collection.png"
  131. alt=""
  132. v-show="item.isFollowGoods == false"
  133. style="width: 20px; height: 20px"
  134. />
  135. <!-- {{ L["收藏"] }} -->
  136. </button>
  137. </div>
  138. </li>
  139. </ul>
  140. <!-- 分页 start -->
  141. <div class="flex_row_center_center sld_pagination" v-if="storeData.goods.list.length">
  142. <el-pagination
  143. @current-change="handleCurrentChange"
  144. v-model:currentPage.sync="pagitionCurrent"
  145. :page-size="storeData.goods.pagination.pageSize"
  146. layout="prev, pager, next"
  147. :total="storeData.goods.pagination.total"
  148. :hide-on-single-page="true"
  149. >
  150. </el-pagination>
  151. </div>
  152. <!-- 分页 end -->
  153. <!-- 空页面 start-->
  154. <SldCommonEmpty
  155. v-if="!firstLoading && !storeData.goods.list.length"
  156. totalWidth="979"
  157. totalHeight="700"
  158. paddingTop="200"
  159. />
  160. <!-- 空页面 end-->
  161. </div>
  162. <!-- 右侧商品 end -->
  163. </div>
  164. </div>
  165. </template>
  166. <script setup>
  167. import { ElMessage, ElPagination } from "element-plus";
  168. // import { lang_zn } from "@/assets/language/zh";
  169. import { getCurLanguage } from '@/composables/common.js';
  170. import { useFiltersStore } from "@/store/filter.js";
  171. const filtersStore = useFiltersStore();
  172. const proxy = getCurrentInstance();
  173. const route = useRoute();
  174. // const L = lang_zn;
  175. const L = getCurLanguage();
  176. const firstLoading = ref(true); //是否第一次加载
  177. const cat_wrap_loading = ref(true)
  178. const router = useRouter();
  179. const storeData = reactive({ cat: [], goods: { list: [], pagination: {} } }); //店铺数据,cat:店铺分类,goods:店铺商品列表
  180. const sort = ref(0); //0:默认/综合;1、销量从高到底;3、价格从低到高;4、价格从高到低;5、人气从高到低
  181. const headercat = ref(null); //获取dom的ref,名字同名
  182. const skeletonData = reactive({ category: [], goods: [] });
  183. const SEOinfo = reactive({
  184. seoTitle: "Products",
  185. seoDesc: "",
  186. seoKeywords: "",
  187. });
  188. //动态页面数据
  189. const vid = ref();
  190. const currentPage = ref(1); //分页——当前页
  191. const categoryId = ref(); //分类id
  192. const keyword = ref(); //搜索关键词
  193. const pagitionCurrent = ref(1)
  194. const storeName = ref('')
  195. //接收店铺名称
  196. const sendGoodsName = (val) => {
  197. storeName.value = val
  198. }
  199. const clacRouteParams = (path, noLoadCat) => {
  200. firstLoading.value = true;
  201. const usePath = path || route.path;
  202. if (calcUrlPagination(usePath)) {
  203. currentPage.value = calcUrlPagination(usePath)
  204. }
  205. if (calcUrlShopId(usePath)) {
  206. vid.value = calcUrlShopId(usePath)
  207. }
  208. if (calcUrlCatId(usePath)) {
  209. categoryId.value = calcUrlCatId(usePath);
  210. }
  211. if (calcUrlKeywords(usePath)) {
  212. keyword.value = calcUrlKeywords(usePath);
  213. }
  214. !noLoadCat && proxy.refs.headercat.setVid(calcUrlShopId(usePath));
  215. getStoreGoodsList();
  216. !noLoadCat && getStoreCatData();
  217. };
  218. watch(
  219. () => currentPage.value,
  220. (nv, ov) => {
  221. if (nv != ov) {
  222. pagitionCurrent.value = Number(nv)
  223. }
  224. }
  225. );
  226. //根据切换数据,改变SEO
  227. const setSEO = () => {
  228. if (categoryId.value == "") {
  229. useHead({
  230. title: "Products",
  231. meta: [
  232. {
  233. name: "description",
  234. content: "Products",
  235. },
  236. {
  237. name: "keywords",
  238. content: "Products",
  239. },
  240. ],
  241. });
  242. return;
  243. }
  244. for (let i in storeData.cat) {
  245. if (storeData.cat[i].innerLabelId == categoryId.value) {
  246. SEOinfo.seoTitle = storeData.cat[i].seoInfo.seoTitle;
  247. SEOinfo.seoDesc = storeData.cat[i].seoInfo.seoDesc;
  248. SEOinfo.seoKeywords = storeData.cat[i].seoInfo.seoKeywords;
  249. break;
  250. } else {
  251. for (let j in storeData.cat[i].children) {
  252. if (storeData.cat[i].children[j].innerLabelId == categoryId.value) {
  253. SEOinfo.seoTitle = storeData.cat[i].children[j].seoInfo.seoTitle;
  254. SEOinfo.seoDesc = storeData.cat[i].children[j].seoInfo.seoDesc;
  255. SEOinfo.seoKeywords =
  256. storeData.cat[i].children[j].seoInfo.seoKeywords;
  257. }
  258. }
  259. }
  260. }
  261. useHead({
  262. title: SEOinfo.seoTitle,
  263. meta: [
  264. {
  265. name: "description",
  266. content: SEOinfo.seoDesc,
  267. },
  268. {
  269. name: "keywords",
  270. content: SEOinfo.seoKeywords,
  271. },
  272. ],
  273. });
  274. };
  275. const initSkeletonData = () => {
  276. for (let i = 0; i < 5; i++) {
  277. skeletonData.category.push({
  278. innerLabelId: "",
  279. innerLabelName: "",
  280. openFlag: true,
  281. children: [
  282. { innerLabelId: "", innerLabelName: "0" },
  283. { innerLabelId: "", innerLabelName: "0" },
  284. { innerLabelId: "", innerLabelName: "0" },
  285. ],
  286. });
  287. }
  288. for (let i = 0; i < 8; i++) {
  289. skeletonData.goods.push({
  290. defaultProductId: "",
  291. goodsImage: "",
  292. goodsPrice: "",
  293. saleNum: "",
  294. activityList: [],
  295. isFollowGoods: false,
  296. });
  297. }
  298. };
  299. //获取店铺分类数据
  300. const getStoreCatData = async (_vid) => {
  301. if (_vid) {
  302. vid.value = _vid;
  303. }
  304. const { data: value } = await useFetchRaw(
  305. apiUrl + "v3/seller/front/store/storeCategory?storeId=" + vid.value
  306. );
  307. const res = value._rawValue;
  308. if (res.state == 200) {
  309. storeData.cat = res.data;
  310. cat_wrap_loading.value = false;
  311. }
  312. setSEO();
  313. };
  314. //获取店铺商品列表
  315. const getStoreGoodsList = async () => {
  316. let param = {};
  317. let key = "";
  318. param.storeId = vid.value;
  319. key += vid;
  320. param.current = currentPage.value;
  321. key += currentPage.value;
  322. if (categoryId.value) {
  323. param.storeInnerLabelId = categoryId.value;
  324. key += categoryId.value;
  325. }
  326. if (keyword.value) {
  327. param.keyword = keyword.value;
  328. key += keyword.value;
  329. }
  330. // param.pageSize = 6;
  331. const { data: value, pending: pending } = await useFetchRaw(
  332. apiUrl + "v3/goods/front/goods/goodsList",
  333. { params: param, key: key, headers:{Authorization:'Bearer ' + filtersStore.getToken }}
  334. );
  335. const res = value._rawValue;
  336. if (!pending._rawValue) {
  337. firstLoading.value = false;
  338. }
  339. if (res.state == 200) {
  340. storeData.goods = res.data;
  341. }
  342. };
  343. const toggleOpenFlag = (key) => {
  344. storeData.cat[key].openFlag =
  345. storeData.cat[key].openFlag != undefined
  346. ? !storeData.cat[key].openFlag
  347. : false;
  348. };
  349. //分页切换/前往指定页面
  350. const handleCurrentChange = (val) => {
  351. currentPage.value = val;
  352. let path = "/store/goods/"+ calcProductName(storeName.value)+"_v-"+ vid.value +"_p-" + val
  353. if(keyword.value && !categoryId.value){
  354. path += "_k-" +keyword.value
  355. }
  356. else if(keyword.value && categoryId.value){
  357. path += "_c-" + categoryId.value +"_k-" +keyword.value
  358. }
  359. else if(!keyword.value && categoryId.value){
  360. path += "_c-" + categoryId.value
  361. }
  362. router.push({
  363. path: path
  364. });
  365. };
  366. watch(categoryId, (newValue, oldValue) => {
  367. if (newValue != oldValue) {
  368. setSEO();
  369. }
  370. });
  371. //收藏功能
  372. const collect = (defaultProductId, isFollowGoods) => {
  373. if (filtersStore.getLoginFlag) {
  374. //收藏功能
  375. let params = {
  376. productIds: defaultProductId,
  377. isCollect: !isFollowGoods,
  378. };
  379. post("v3/member/front/followProduct/edit", params).then((res) => {
  380. if (res.state == 200) {
  381. ElMessage.success(res.msg);
  382. storeData.goods.list.map((storeGoodsItem) => {
  383. if (storeGoodsItem.defaultProductId == defaultProductId) {
  384. storeGoodsItem.isFollowGoods = !storeGoodsItem.isFollowGoods;
  385. }
  386. });
  387. } else {
  388. ElMessage.error(res.msg);
  389. }
  390. });
  391. } else {
  392. //未登录的话提示登录
  393. return openLoginDialog({
  394. onRegister: () => {
  395. router.push({
  396. path: "/register",
  397. });
  398. },
  399. onForgot: () => {
  400. router.push({
  401. path: "/member/login/forget",
  402. });
  403. },
  404. });
  405. }
  406. };
  407. onMounted(() => {
  408. setTimeout(() => {
  409. sldStatEvent({ behaviorType: 'spv', storeId: vid.value ,pageUrl: defaultUrl + router.currentRoute.value.path, referrerPageUrl: apiUrl });
  410. }, 3000)
  411. initSkeletonData();
  412. nextTick(() => {
  413. clacRouteParams();
  414. });
  415. });
  416. </script>
  417. <style lang="scss" scoped>
  418. @import "@/assets/style/store/goodsList.scss";
  419. @import "@/assets/style/theme.scss";
  420. .el-pager li.active {
  421. color: $colorMain;
  422. cursor: default;
  423. }
  424. .el-pager li:hover {
  425. color: $colorMain;
  426. }
  427. .sld_pagination {
  428. margin: 20px 0 20px 0;
  429. }
  430. .store_goods_search_nav {
  431. cursor: pointer;
  432. }
  433. </style>